home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 1 / Deutsche Edition 1.iso / amok / amok_lha / amok05.lha / PrintIt! / PrintIt.mod < prev    next >
Text File  |  1993-08-15  |  14KB  |  423 lines

  1. (*---------------------------------------------------------------------------
  2.     :Program.    PrintIt.mod
  3.     :Author.     Fridtjof Siebert
  4.     :Address.    Nobileweg 67, D-7-Stgt-40
  5.     :Phone.      0711/822509
  6.     :Shortcut.   [fbs]
  7.     :Version.    1.0
  8.     :Date.       14-Jul-88
  9.     :Copyright.  PD
  10.     :Language.   Modula-II
  11.     :Translator. M2Amiga
  12.     :Imports.    IFFLoad  [fbs] (Amok#2 or Amok#3).
  13.     :UpDate.     none.
  14.     :Contents.   Utility to create high-quality Hardcopies Epson-Printers.
  15.     :Remark.     Welche Drucker (außer Citizen 120D) können 144 dots/inch ??
  16. ---------------------------------------------------------------------------*)
  17.  
  18. (*-------------------------------------------------------------------------*)
  19. (*                                                                         *)
  20. (*                     =   =   =   PrintIt !   =   =   =                   *)
  21. (*                                                                         *)
  22. (*  A Graphics-Print Utilities for Epson FX-compatible Printers that       *)
  23. (*  use the ESC/P Standard codes. They should be able to print in          *)
  24. (*  quadruple density.                                                     *)
  25. (*                                                                         *)
  26. (*  This Programm allows you to make really black Hardcopies. It uses      *)
  27. (*  the highest possible horizontal & vertical density, i.e. 240 dpi       *)
  28. (*  and 216 dpi. Your Hardcopys will be stretched a bit (11% higher than   *)
  29. (*  they should be) but this normally isn't too important.                 *)
  30. (*                                                                         *)
  31. (*  PrintIt uses PAR: to print. So don't plug your Printer into SER: (I    *)
  32. (*  don't know, if that is possible, but don't do it!).                    *)
  33. (*                                                                         *)
  34. (*  PrintIt has been developed on a Citizen 120D, which is a very cheap,   *)
  35. (*  but good Printer. If you use other Epson compatible Printers, there    *)
  36. (*  should be no problems. Tell me if there are any !!!                    *)
  37. (*                                                                         *)
  38. (*  © 1988 by Fridtjof Siebert                                             *)
  39. (*            Nobileweg 67                                                 *)
  40. (*            D-7000-Stuttgart-40                                          *)
  41. (*            Phone: (0)711/822509                                         *)
  42. (*                                                                         *)
  43. (*  Contributions wellcome.                                                *)
  44. (*                                                                         *)
  45. (*-------------------------------------------------------------------------*)
  46.  
  47. MODULE PrintIt;
  48.  
  49. (*--------------------------  IMPORTs:  -----------------------------------*)
  50.  
  51. (*------  SYSTEM:  ------*)
  52. FROM SYSTEM         IMPORT ADR, SHIFT, BITSET, INLINE;
  53. FROM Arts           IMPORT TermProcedure, Assert;
  54. FROM Arguments      IMPORT GetArg, NumArgs;
  55.  
  56. (*------  Libraries:  ------*)
  57. FROM Dos            IMPORT Open, Close, FileHandlePtr, Write, Read, oldFile,
  58.                            newFile, Delay;
  59. FROM Exec           IMPORT AllocMem, FreeMem, MemReqs, MemReqSet, UByte,
  60.                            WaitPort, GetMsg, ReplyMsg;
  61. FROM Intuition      IMPORT ScreenPtr, WindowPtr, CloseScreen, CloseWindow,
  62.                            IntuiMessagePtr, GadgetPtr, IDCMPFlags,
  63.                            ScreenToFront, WBenchToFront, SetPointer,
  64.                            ClearPointer;
  65.  
  66. (*------  Own stuff:  ------*)
  67. FROM IFFLoad        IMPORT ReadILBM, ReadILBMFlags, ReadILBMFlagSet, IFFInfo;
  68. (* IFFLoad from AMOK#2 or #3 *)
  69. FROM PrintItDisplay IMPORT OpenPrintIt, Window, Gadgets, RP, TextType,
  70.                            GetName, InitPrintIt, StretchX, StretchY,
  71.                            DoublePrint, xRes, yRes, Positive, PixName,
  72.                            Screen, Convert, StrInfo, Buffers;
  73.  
  74. (*-----------------------  Variables:  ------------------------------------*)
  75.  
  76. TYPE
  77.   BufferType = ARRAY[0..8249] OF UByte; (* I/O Buffer for PAR: *)
  78.  
  79. VAR
  80.   MyFile: FileHandlePtr;                (* FileHandlePtr for PAR: *)
  81.   Buffer: POINTER TO BufferType;        (* It's Buffer            *)
  82.   DummyWindow: WindowPtr;               (* not too important      *)
  83.   ok: BOOLEAN;
  84.   i: CARDINAL;
  85.   j: INTEGER;
  86.   len: LONGINT;
  87.   ActLine, CountLines, CountBits, CountBytes: CARDINAL; (* Count anything *)
  88.   RepHorCnt,RepVerCnt: LONGINT;         (* Count Repeats          *)
  89.   ActByte: UByte;                       (* the calcylated Byte    *)
  90.   ActAdr: POINTER TO BITSET;            (* Position in BitMap     *)
  91.   SmallOrBig: CARDINAL;                 (* Counts Printed lines   *)
  92.   Msg: IntuiMessagePtr;
  93.   Gadget: GadgetPtr;
  94.   WaitPointer,DataPtr: POINTER TO ARRAY[0..17] OF LONGCARD;
  95.  
  96. (*-------------------------------------------------------------------------*)
  97. (*                                                                         *)
  98. (*                        The Main Print-Procedure                         *)
  99. (*                                                                         *)
  100. (*-------------------------------------------------------------------------*)
  101.  
  102. PROCEDURE PrintIt();
  103.  
  104. BEGIN
  105.  
  106.   RepVerCnt := 0;
  107.   REPEAT
  108.  
  109. (*------  Set LF:  ------*)
  110.  
  111.     Buffer^[0] := 1BH;
  112.     CASE yRes OF
  113.     DpiV72ID:
  114.       Buffer^[1] := 33H; Buffer^[2] := 23;
  115.       len := Write(MyFile,Buffer,3); |
  116.     DpiV144ID:
  117.       Buffer^[1] := 7EH; Buffer^[2] := 30H; Buffer^[3] := 1;
  118.       len := Write(MyFile,Buffer,4); |
  119.     DpiV216ID:
  120.       Buffer^[1] := 33H; Buffer^[2] := 1;
  121.       len := Write(MyFile,Buffer,3);
  122.     END;
  123.  
  124. (*------  Main Printing-Loop:  ------*)
  125.  
  126.     CountLines := 0;  (* Line 0                 *)
  127.     SmallOrBig := 0;  (* Counts small or big LF *)
  128.  
  129.     WITH Screen^.bitMap DO
  130.  
  131. (*------  LOOP for Lines:  ------*)
  132.  
  133.       WHILE (CountLines DIV StretchY) < rows DO
  134.  
  135.         CountBytes := 0; (* Num of Bytes printed per Line *)
  136.         CountBits := 0;  (* x-Position in BitMap          *)
  137.  
  138. (*------  LOOP to print a Line:  ------*)
  139.  
  140.         WHILE SHIFT(CountBits,-3) < bytesPerRow DO
  141.  
  142.           ActByte := 0;
  143.           i := 0;
  144.  
  145. (*------  LOOP to get 8 Bits:  ------*)
  146.  
  147.           LOOP
  148.  
  149.             CASE yRes OF
  150.               DpiV72ID : ActLine := CountLines + i; |
  151.               DpiV144ID: ActLine := CountLines + i+i; |
  152.               DpiV216ID: ActLine := CountLines + i+i+i; |
  153.             END;
  154.             ActLine := ActLine DIV StretchY;
  155.             IF ActLine >= rows THEN EXIT END;
  156.  
  157.             ActByte := SHIFT(ActByte,1);
  158.             ActAdr := planes[0];
  159.             INC(ActAdr,ActLine * bytesPerRow + SHIFT(SHIFT(CountBits,-4),1));
  160.  
  161.             IF 15 - (CountBits-SHIFT(SHIFT(CountBits,-4),4)) IN ActAdr^ THEN
  162.               INC(ActByte,1); (* Bit Set *)
  163.             END;
  164.  
  165.             INC(i);
  166.             IF i=8 THEN EXIT END;
  167.  
  168.           END;
  169.  
  170.           IF NOT(Positive) THEN
  171.             CASE i OF
  172.               8: ActByte := 255-ActByte; |
  173.               7: ActByte := 127-ActByte; |
  174.               6: ActByte :=  63-ActByte; |
  175.               5: ActByte :=  31-ActByte; |
  176.               4: ActByte :=  15-ActByte; |
  177.               3: ActByte :=   7-ActByte; |
  178.               2: ActByte :=   3-ActByte; |
  179.               1: ActByte :=   1-ActByte; |
  180.             END;
  181.           END;
  182.           ActByte := SHIFT(ActByte,8-i);
  183.  
  184.           i := 0;
  185.           REPEAT
  186.             Buffer^[CountBytes+5] := ActByte; (* Byte to Printer's Buffer *)
  187.             INC(CountBytes); (* Next Byte to Printer *)
  188.             INC(i);
  189.           UNTIL i=StretchX; (* Byte StretchX times into Buffer *)
  190.           INC(CountBits);  (* 1 Pixel to the right *)
  191.  
  192.         END;
  193.  
  194. (*------  Print one Line:  ------*)
  195.  
  196.         Buffer^[0] := 1BH; Buffer^[1] := 2AH;
  197.         CASE xRes OF
  198.           DpiH60ID:  Buffer^[2] := 0; |
  199.           DpiH72ID:  Buffer^[2] := 5; |
  200.           DpiH80ID:  Buffer^[2] := 4; |
  201.           DpiH90ID:  Buffer^[2] := 6; |
  202.           DpiH120ID: Buffer^[2] := 1; |
  203.           DpiH144ID: Buffer^[2] := 7; |
  204.           DpiH240ID: Buffer^[2] := 3; |
  205.         END;
  206.         Buffer^[3] := UByte(CountBytes - SHIFT(SHIFT(CountBytes,-8),8));
  207.         Buffer^[4] := UByte(SHIFT(CountBytes,-8));
  208.         Buffer^[CountBytes+5] := 0DH; (* CR *)
  209.         Buffer^[CountBytes+6] := 0AH; (* LF *)
  210.         IF DoublePrint THEN
  211.           RepHorCnt := 0;
  212.           REPEAT
  213.             len := Write(MyFile,Buffer,CountBytes+5);      (* Print Line *)
  214.             INC(RepHorCnt);
  215.           UNTIL RepHorCnt >= StrInfo[RepHorID].longInt;
  216.           len := Write(MyFile,ADR(Buffer^[CountBytes+5]),1); (* CR *)
  217.         END;
  218.         RepHorCnt := 0;
  219.         REPEAT
  220.           len := Write(MyFile,Buffer,CountBytes+5);        (* Print Line *)
  221.           INC(RepHorCnt);
  222.         UNTIL RepHorCnt >= StrInfo[RepHorID].longInt;
  223.         len := Write(MyFile,ADR(Buffer^[CountBytes+5]),2); (* CR + LF *)
  224.  
  225. (*------  Increase CountLines and set next LF-Size:  ------*)
  226.  
  227.         INC(SmallOrBig);
  228.         CASE yRes OF
  229.         DpiV72ID:
  230.           INC(CountLines,8); |
  231.         DpiV144ID:
  232.           Buffer^[0] := 1BH; Buffer^[1] := 7EH;
  233.           Buffer^[2] := 30H;
  234.           CASE SmallOrBig OF
  235.           2: SmallOrBig := 0;
  236.              INC(CountLines,15);
  237.              Buffer^[3] := 1;  |
  238.           1: INC(CountLines);
  239.              Buffer^[3] := 15; |
  240.           END;
  241.           len := Write(MyFile,Buffer,4); |
  242.         DpiV216ID:
  243.           Buffer^[0] := 1BH; Buffer^[1] := 33H;
  244.           CASE SmallOrBig OF
  245.           3: SmallOrBig := 0;
  246.              Buffer^[2] := 1H;     (* small LF: 1/216''             *)
  247.              INC(CountLines,22); | (* 3 Lines done: get a bit down. *)
  248.           2: Buffer^[2] := 16H;    (* next is a big LF (22/216'')   *)
  249.              INC(CountLines); |    (* next Line                     *)
  250.           1: Buffer^[2] := 1H;     (* 1/216''                       *)
  251.              INC(CountLines); |    (* next Line                     *)
  252.           END;
  253.           len := Write(MyFile,Buffer,3); (* set LF-Size *)
  254.         END;
  255.  
  256.       END;   (* WHILE (CountLines DIV StretchY) < rows DO *)
  257.  
  258.     END;   (* WITH Screen^.bitMap DO *)
  259.  
  260.     INC(RepVerCnt);
  261.  
  262.   UNTIL RepVerCnt >= StrInfo[RepVerID].longInt;
  263.  
  264. END PrintIt;
  265.  
  266. (*-----------------------  CleanUp:  --------------------------------------*)
  267.  
  268. PROCEDURE CleanUp();
  269.  
  270. BEGIN
  271.   IF Window#NIL THEN CloseWindow(Window) END;
  272.   IF Screen#NIL THEN CloseScreen(Screen) END;
  273.   IF MyFile#NIL THEN Close(MyFile); END;
  274.   IF Buffer#NIL THEN FreeMem(Buffer,SIZE(Buffer^)) END;
  275.   IF WaitPointer#NIL THEN FreeMem(WaitPointer,SIZE(WaitPointer^)) END;
  276. END CleanUp;
  277.  
  278. (*------  Some Data:  ------*)
  279.  
  280. PROCEDURE PointerData(); (* $E- Contains SpriteData: *)
  281.  
  282. BEGIN
  283.   INLINE(0,0,
  284.          0003FH,00000H,0007FH,00021H,0007FH,00000H,000FEH,00042H,
  285.          000FEH,00000H,001FCH,00084H,001FCH,00000H,003F8H,00108H,
  286.          00FFFH,00C07H,017F1H,01A1FH,027F3H,038CFH,04005H,07FFFH,
  287.          0FFF9H,0FFFFH,0800AH,0FFFEH,0800CH,0FFFCH,0FFF8H,0FFF8H,0,0);
  288. END PointerData;
  289.  
  290. (*---------------------------  MAIN:  -------------------------------------*)
  291.  
  292. BEGIN
  293.  
  294. (*------  Itialization:  ------*)
  295.  
  296.   Screen := NIL;
  297.   MyFile := NIL;
  298.   Buffer := NIL;
  299.   Window := NIL;
  300.   WaitPointer := NIL;
  301.   TermProcedure(CleanUp);
  302.  
  303. (*------  Get Memory for Pointer:  ------*)
  304.  
  305.   WaitPointer := AllocMem(SIZE(WaitPointer^),MemReqSet{chip});
  306.   Assert(WaitPointer#NIL,ADR("Not enough Chip Memory !!!"));
  307.   DataPtr := ADR(PointerData);
  308.   WaitPointer^ := DataPtr^;
  309.  
  310. (*------  Get Argument:  ------*)
  311.  
  312.   IF NumArgs()=0 THEN
  313.     GetName();
  314.   ELSE
  315.     GetArg(1,PixName,j);
  316.   END;
  317.  
  318. (*------  Load Pic:  ------*)
  319.  
  320.   WHILE NOT(ReadILBM(PixName,ReadILBMFlagSet{front,visible},Screen,
  321.         DummyWindow)) DO
  322.     ok := WBenchToFront();
  323.     GetName();
  324.   END;
  325.   ok := WBenchToFront();
  326.   IF Screen^.bitMap.depth > 1 THEN
  327.     Convert();
  328.   END;
  329.  
  330. (*------  Open Window:  ------*)
  331.  
  332.   OpenPrintIt();
  333.   InitPrintIt();
  334.  
  335. (*------  Open PAR:  ------*)
  336.  
  337.   MyFile := Open(ADR("PAR:"),newFile);
  338.   Assert(MyFile#NIL,ADR("Couldn't open PAR: !!!"));
  339.   Buffer := AllocMem(SIZE(BufferType),MemReqSet{chip});
  340.   Assert(Buffer#NIL,ADR("Not enough Chip Memory !!!"));
  341.  
  342. (*------  Get Messages:  ------*)
  343.  
  344.   LOOP
  345.     WaitPort(Window^.userPort);
  346.     Msg := GetMsg(Window^.userPort);
  347.     IF closeWindow IN Msg^.class THEN
  348.       ReplyMsg(Msg);
  349.       EXIT;
  350.     END;
  351.     Gadget := Msg^.iAddress;
  352.     ReplyMsg(Msg);
  353.  
  354.     CASE Gadgets(Gadget^.gadgetID) OF
  355.  
  356.     hori1ID..hori8ID:
  357.       StretchX := Gadget^.gadgetID + 1; |
  358.  
  359.     vert1ID..vert8ID:
  360.       StretchY := Gadget^.gadgetID - 7; |
  361.  
  362.     PrintNormalID:
  363.       DoublePrint := FALSE; |
  364.  
  365.     PrintDoubleID:
  366.       DoublePrint := TRUE; |
  367.  
  368.     PrintItID:
  369.       ScreenToFront(Screen);
  370.       SetPointer(Window,WaitPointer,16,16,-8,-8);
  371.       PrintIt();
  372.       ClearPointer(Window);
  373.       ok := WBenchToFront(); |
  374.  
  375.     DpiH60ID..DpiH240ID:
  376.       xRes := Gadgets(Gadget^.gadgetID); |
  377.  
  378.     DpiV72ID..DpiV216ID:
  379.       yRes := Gadgets(Gadget^.gadgetID); |
  380.  
  381.     PositiveID:
  382.       Positive := NOT(Positive); |
  383.  
  384.     RepHorID..RepVerID:
  385.       WITH StrInfo[Gadgets(Gadget^.gadgetID)] DO
  386.         IF longInt<1 THEN
  387.           longInt := 1;
  388.         END;
  389.       END; |
  390.  
  391.     LoadPicID:
  392.       CloseScreen(Screen);
  393.       Screen := NIL;
  394.       REPEAT
  395.         ClearPointer(Window);
  396.         GetName();
  397.         SetPointer(Window,WaitPointer,16,16,-8,-8);
  398.       UNTIL ReadILBM(PixName,ReadILBMFlagSet{front,visible},Screen,
  399.             DummyWindow);
  400.       ClearPointer(Window);
  401.       ok := WBenchToFront();
  402.       IF Screen^.bitMap.depth > 1 THEN
  403.         Convert();
  404.       END; |
  405.  
  406.     ResetID:
  407.       StretchX := 1; StretchY := 1;
  408.       DoublePrint := FALSE;
  409.       xRes := DpiH240ID;
  410.       yRes := DpiV216ID;
  411.       Positive := TRUE;
  412.       StrInfo[RepHorID].longInt := 1;
  413.       Buffers[RepHorID] := "1";
  414.       StrInfo[RepVerID].longInt := 1;
  415.       Buffers[RepVerID] := "1"; |
  416.     END;
  417.  
  418.     InitPrintIt();
  419.  
  420.   END; (* LOOP *)
  421.  
  422. END PrintIt. That's it.
  423.